#include "clock.h"
#include "ti_msp_dl_config.h"

volatile unsigned long tick_ms;
volatile uint32_t start_time;

int mspm0_delay_ms(unsigned long num_ms) {
  start_time = tick_ms;
  while (tick_ms - start_time < num_ms)
    ;
  return 0;
}

int mspm0_get_clock_ms(unsigned long *count) {
  if (!count)
    return 1;
  count[0] = tick_ms;
  return 0;
}
void mspm0_delay_us(unsigned long us) {
#define _1_US_CYCLE (CPUCLK_FREQ / 1000000)
  delay_cycles(us * _1_US_CYCLE);
}

void SysTick_Init(void) {
  DL_SYSTICK_config(CPUCLK_FREQ / 1000);
  NVIC_SetPriority(SysTick_IRQn, 0);
}
